package org.dream.service;

// Generated 2009-9-13 14:47:42 by Hibernate Tools 3.2.4.GA with hssgen

import java.util.Collections;
import java.util.List;
import java.util.Vector;

import org.dream.domain.Daydeal;
import org.dream.persistence.HibernateSessionFactory;
import org.dream.persistence.PersistenceService;
import org.dream.persistence.PersistenceServiceImpl;
import org.dream.util.DoubleUtil;

/**
 * @author qiuriyuchen E-mail:panpan_001@126.com
 */
public class DaydealService {
	private static List<Daydeal> listAll;
	private ImportService fileStockService = new ImportServiceImpl();
	private PersistenceService persistenceService=new PersistenceServiceImpl();

	/**
	 * 得到全部股票日线数据
	 */
	public synchronized List<Daydeal> getListAll() {
		if (listAll == null) {
			listAll = HibernateSessionFactory.getSession().createQuery("from Daydeal").list();
			Collections.sort(listAll);
		}
		return listAll;
	}

	/**
	 * 得到量线
	 */
	public Vector<Vector<Object>> getDaydealTurnoverTable(String code, String startDate, String endDate,
			double zhangFu, double liangZhangFu) {

		Vector<Vector<Object>> data = new Vector<Vector<Object>>();
		List<Daydeal> listDaydeal = persistenceService.findDayDealsByCode(code);
		new HLYService().countJlScore(listDaydeal);
		if (listDaydeal == null) {
			return null;
		}
		for (Daydeal daydeal : listDaydeal) {
			if (daydeal.isDaliang(liangZhangFu) && daydeal.isDaZhangFu(zhangFu)
					&& daydeal.getDAY().compareTo(startDate) > 0 && daydeal.getDAY().compareTo(endDate) < 0
					&& daydeal.isDaZhangFu(3)) {
				Vector<Object> row = new Vector<Object>();
				row.add(daydeal.getDayNum());
				row.add(daydeal.getDAY());
				row.add(daydeal.getCode());
				row.add(daydeal.getName());
				row.add(daydeal.getCLOSE());
				row.add(daydeal.getVOL());
				row.add(DoubleUtil.scale2(daydeal.getRiseWidth()));
				row.add(DoubleUtil.scale2(daydeal.getVOLRiseWidth()));
				row.add(daydeal.getJlScore());
				row.add(daydeal.getJlScoreTotal());
				data.add(row);
			}

		}
		return data;
	}

}
